<!--
  * 部门 树形选择框

  * @Author:    1024创新实验室-主任：卓大
  * @Date:      2022-09-12 23:05:43
  * @Wechat:    zhuda1024
  * @Email:     lab1024@163.com
  * @Copyright  1024创新实验室 （ https://1024lab.net ），Since 2012
  *
-->
<template>
  <a-select
    :field-names="{ label: 'siteName', value: 'siteId' }"
    :value="props.value"
    style="width: 100%"
    :showSearch="true"
    @change="onChange"
    :options="treeData"
    :filter-option="filterOption"
  >
  </a-select>
</template>
<script setup>


import { onMounted, ref } from 'vue';


import { siteordApi } from '/@/api/business/erp/siteord-api';

const props = defineProps({
  // 绑定值
  value: String,
  // 单选多选
  multiple: {
    type: Boolean,
    default: false,
  },
});

const emit = defineEmits(['update:value']);

let treeData = ref([]);

onMounted(vendmentTree);

function vendmentTree() {

  siteordApi
    .queryPage({
      pageNum: 1,
      pageSize: 10,
    })
    .then((res) => {
      treeData.value = res.data.list;
    })
    .finally(() => {

    });
}

function onChange(e, { siteName }) {
  emit('update:value', e, siteName);
}

function filterOption(input, option) {
  return option.siteName.includes(input);
}
</script>
